package com.webservice.config;

import com.webservice.service.GreetWebService;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * 业务聚合
 *
 * @version [V2.0]
 * @package com.example.demo;
 * @description:[用一句话描述该文件做什么]
 * @author: [zhuben]
 * @date: [2022/12/22 16:28]
 * @copyright: 2022 echovin.com
 */
@Configuration
public class CxfConfig {
    @Autowired
    private GreetWebService greetWebService;

    @Autowired
    private Bus bus;

    /**
     * 发布服务
     * @return
     */
    @Bean
    public Endpoint userServiceEndpoint() {
        System.out.println("服务发布");
        //这里指定的端口不能跟应用的端口冲突, 单独指定
        String path = "http://127.0.0.1:9000/greet";
        EndpointImpl userEndpoint = new EndpointImpl(bus, greetWebService);
        userEndpoint.publish(path);

        System.out.println("服务成功，path: " + path);
        System.out.println(String.format("在线的wsdl：%s?wsdl", path));
        return userEndpoint;
    }
}
